import request from '@/utils/request'
import upload from '../../utils/upload'

// 查询我的模版
export function getMyTemplates() {
	return request({
		url: '/youqiu/activity/template',
		method: 'get',
	}).then(res => {
		if(res.code === 200 && res.data) {
			res.data = res.data.map(template => ({
				id: template.id,
				title: template.title,
				createTime: template.create_time,
				...JSON.parse(template.template || '{}')
			}))
		}
		return res
	})
}

// 查询活动分类
export function listSportType(query) {
	return request({
		url: '/system/dict/data/type/' + query,
		method: 'get',
		//params: query
	})
}

// 上传活动封面
export function uploadCover(data) {
	return upload({
		url: '/system/oss/upload',
		name: data.name,
		filePath: data.filePath
	})
}

// 查询活动列表
export function listActivity(query) {
	return request({
		url: '/youqiu/activity/list',
		method: 'get',
		params: query
	})
}

// 根据用户id查询活动列表
export function listActivityByUserId(query) {
	return request({
		url: '/youqiu/activity/listByUserId',
		method: 'get',
		params: query
	})
}

// 查询活动详细
export function getActivity(id) {
	return request({
		url: '/youqiu/activity/' + id,
		method: 'get'
	})
}

// 新增活动
export function addActivity(data) {
	return request({
		url: '/youqiu/activity',
		method: 'post',
		data: data
	})
}

// 修改活动
export function updateActivity(data) {
	return request({
		url: '/youqiu/activity',
		method: 'put',
		data: data
	})
}

// 删除活动
export function delActivity(id) {
	return request({
		url: '/youqiu/activity/' + id,
		method: 'delete'
	})
}
